﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.ResponseButtons.Service
{
    public class ResponseButtonAppService : BaseAppService, IResponseButtonAppService
    {
        private IResponseButtonDomainService _domainService;

        public ResponseButtonAppService(IResponseButtonDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSEBUTTON, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSEBUTTON, AuditAction.CREATE)]
        public ResponseButtonDto Add(Guid resopnseId, ResponseButtonCreateDto dto)
        {
            dto.ResponseId = resopnseId;
            ResponseButton responseButton = _domainService.Create(Mapper.Map<ResponseButton>(dto));
            return Mapper.Map<ResponseButtonDto>(responseButton);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSEBUTTON, AuditAction.UPDATE)]
        public ResponseButtonDto Update(Guid id, ResponseButtonUpdateDto dto)
        {
            ResponseButton responseButton = _domainService.Update(Mapper.Map<ResponseButtonUpdateBo>(dto));
            return Mapper.Map<ResponseButtonDto>(responseButton);
        }

        public ResponseButtonDto Get(Guid id, string include)
        {
            ResponseButton responseButton = _domainService.Get(id, include);
            return Mapper.Map<ResponseButtonDto>(responseButton);
        }

        public IEnumerable<ResponseButtonDto> GetList(Guid responseId, string include)
        {
            IEnumerable<ResponseButton> list = _domainService.GetByResponseId(responseId, include);
            return Mapper.Map<IEnumerable<ResponseButtonDto>>(list);
        }
    }
}
